<?php
class Login extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->database();
		$this->load->model('login_model');

	}

	function index(){
		$this->load->view('login_view');
	}

	function signup(){
		$this->load->view('signup_view');
	}

	function check2(){
		$username=$_GET['username'];
		$status =$this->login_model->check_name($username);
		// echo $status;
		if($status){
			echo '1';
		}else{
			echo  '0';
		}
	}

	function sign(){
		$nd['username']=$_POST['username'];
		$nd['password']=md5($_POST['password']);
		$nd['add_time']= date('Y-m-d H:i:s');
		$nd['updata_time']= date('Y-m-d H:i:s');
		$nd['delete_time']= date('Y-m-d H:i:s');
		$this->login_model->insert($nd);
		redirect('welcome/index');
	}


	function log(){
		$name = $_POST['username1'];
		$pw = md5($_POST['password1']);
		//echo $name.$pw;
		$check = $this->login_model->check1($name,$pw);
		//echo $check;
		if($name && $pw){
         if($check){
         	$session['username1'] = $name;	
         	//echo 	$session['username1'];
         	$this->session->set_userdata($session);
         	echo    '1';
         }else{
         	echo   '0';
         }
		}

		//echo '<script>window.location.href="http://localhost/633games/index.php/welcome/index" </script>';
	}

	function destory(){
		$this->session->sess_destroy();
		redirect('login/index');
	}
}
